<?php
/**
 * Magento Enterprise Edition
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Magento Enterprise Edition End User License Agreement
 * that is bundled with this package in the file LICENSE_EE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.magento.com/license/enterprise-edition
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    design
 * @package     enterprise_default
 * @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
 * @license http://www.magento.com/license/enterprise-edition
 */
?>
<div class="page-title">
    <h1><?php echo $this->getFormHeader() ?></h1>
</div>
<span id="gr-please-wait" class="please-wait" style="display:none;">
    <img src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif') ?>" alt="" class="v-middle" /> <?php echo $this->__('Please wait, loading...') ?>
</span>

<?php echo $this->getMessagesBlock()->toHtml(); ?>
<form action="<?php echo $this->getActionUrl() ?>" method="post" id="gr_search_form">
    <div class="fieldset">
        <?php echo $this->getBlockHtml('formkey')?>
        <h2 class="legend"><?php echo $this->__('Search Options') ?></h2>
        <ul class="form-list">
            <li>
                <label for="params_type_id"><?php echo $this->__('Gift Registry Type') ?></label>
                <div class="input-box">
                    <?php echo $this->getTypeSelectHtml() ?>
                </div>
                <p class="note"><?php echo $this->__('To make search results narrower, specify gift registry type prior to searching. By default, all registry types are searched.') ?></p>
            </li>
            <li class="fields">
                <div class="field">
                    <label for="params_firstname" class="required"><em>*</em><?php echo $this->__('First Name') ?></label>
                     <div class="input-box">
                        <input name="params[firstname]" id="params_firstname" type="text" value="<?php echo $this->getFormData('firstname') ?>" class="input-text required-entry" />
                    </div>
                </div>
                <div class="field">
                    <label for="params_lastname" class="required"><em>*</em><?php echo $this->__('Last Name') ?></label>
                    <div class="input-box">
                        <input name="params[lastname]" id="params_lastname" type="text" value="<?php echo $this->getFormData('lastname') ?>" class="input-text required-entry" />
                    </div>
                </div>
            </li>
        </ul>
    </div>

    <div class="fieldset" id="gr-type-specific-fieldset" style="display:none;">
        <h2 class="legend"><?php echo $this->__('Type Specific Options') ?></h2>
        <ul class="form-list">
            <li class="fields" id="gr-type-specific-options">
            </li>
        </ul>
    </div>

    <div class="buttons-set form-buttons">
        <input type="hidden" name="params[search]" value="type" />
        <button type="submit" class="button"><span><span><?php echo $this->__('Search') ?></span></span></button>
    </div>
    <p class="required"><?php echo $this->__('* Required Fields') ?></p>
</form>

<div class="divider"></div>

<form action="<?php echo $this->getActionUrl() ?>" method="post" id="gr_search_email_form">
    <div class="fieldset">
        <ul class="form-list">
            <li>
                 <label for="params_email" class="required"><em>*</em><?php echo $this->__('Recipient Email') ?></label>
                 <div class="input-box">
                     <input name="params[email]" id="params_email" type="text" value="<?php echo $this->getFormData('email') ?>" class="input-text required-entry validate-email" />
                 </div>
            </li>
        </ul>
    </div>
    <div class="buttons-set form-buttons">
        <input type="hidden" name="params[search]" value="email" />
        <button type="submit" class="button"><span><span><?php echo $this->__('Search') ?></span></span></button>
    </div>
    <p class="required"><?php echo $this->__('* Required Fields') ?></p>
</form>

<div class="divider"></div>

<form action="<?php echo $this->getActionUrl() ?>" method="post" id="gr_search_id_form">
    <div class="fieldset">
        <ul class="form-list">
            <li>
                 <label for="params_id" class="required"><em>*</em><?php echo $this->__('Gift Registry ID') ?></label>
                 <div class="input-box">
                     <input name="params[id]" id="params_id" type="text" value="<?php echo $this->getFormData('id') ?>" class="input-text required-entry" />
                 </div>
            </li>
        </ul>
    </div>
    <div class="buttons-set form-buttons">
        <input type="hidden" name="params[search]" value="id" />
        <button type="submit" class="button"><span><span><?php echo $this->__('Search') ?></span></span></button>
    </div>
    <p class="required"><?php echo $this->__('* Required Fields') ?></p>
</form>

<script type="text/javascript">
//<![CDATA[
var grSearchForm = new VarienForm('gr_search_form');
var grSearchEmailForm = new VarienForm('gr_search_email_form');
var grSearchIdForm = new VarienForm('gr_search_id_form');

function advancedFormUpdate() {
    new Ajax.Updater('gr-type-specific-options', '<?php echo $this->getAdvancedUrl() ?>', {
        evalScripts : true,
        onCreate: function() {
            $('gr-please-wait').show()
        },
        onComplete: function() {
            $('gr-please-wait').hide();
        },
        parameters : {type_id : $('params_type_id').value}
    });
}
$('params_type_id').observe('change', advancedFormUpdate);

<?php if ($this->getFormData('type_id')): ?>
    $A($('params_type_id').options).each(function(option){
        if (option.value==<?php echo (int)$this->getFormData('type_id') ?>) option.selected = true;
    });
    advancedFormUpdate();
<?php endif; ?>
//]]>
</script>

<?php if ($this->getSearchResults() && $this->getSearchResults()->getSize()): ?>
<div class="fieldset">
    <h2 class="legend"><?php echo $this->__('Search Results') ?></h2>
</div>
<?php echo $this->getChildHtml('pager') ?>
<table class="data-table" id="giftregistry-search-results">
    <thead>
        <tr>
            <th><?php echo $this->__('Name') ?></th>
            <th><?php echo $this->__('Location') ?></th>
            <th class="a-center"><?php echo $this->__('Event') ?></th>
            <th class="a-center"><?php echo $this->__('Type') ?></th>
            <th class="a-center"><?php echo $this->__('Event Date') ?></th>
            <th class="a-center"></th>
        </tr>
    </thead>
    <tbody>
    <?php foreach($this->getSearchResults() as $item): ?>
        <tr>
            <td><?php echo $this->escapeHtml($item->getRegistrant()) ?></td>
            <td><?php echo $this->escapeHtml($item->getEventLocation()) ?></td>
            <td><?php echo $this->escapeHtml($item->getTitle()) ?></td>
            <td><?php echo $this->escapeHtml($item->getType()) ?></td>
            <td><?php echo $this->getFormattedDate($item) ?></td>
            <td><a href="<?php echo $this->getRegistryLink($item) ?>"><?php echo $this->__('View') ?></a></td>
        </tr>
    <?php endforeach; ?>
    </tbody>
</table>
<script type="text/javascript">decorateTable('giftregistry-search-results')</script>
<?php echo $this->getChildHtml('pager') ?>
<?php elseif ($this->getSearchResults()): ?>
    <?php echo $this->__('Your search returns no results.') ?>
<?php endif; ?>
